package com.example.demo.hcontroller;

import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.example.demo.pojo.Result;
import com.example.demo.service.IResultService;

@Controller
@RequestMapping("/hResult")
public class HResultController {

	
	@Resource
	private IResultService ResultService;

	@RequestMapping("/toResult")
	private String toResult(Model model){
		List<Result> Resultlist=ResultService.selectResult();
		model.addAttribute("resultlist", Resultlist);
		return "result";
	}

	@RequestMapping("/toaddResult")
	private String toaddResult(Model model){
		return "addresult";
	}
	@RequestMapping("/addResult")
	public String addResult(Result Result, Integer rsnum, Integer renum, String result, Integer mid) throws IOException {
		Result.setMid(1);
		Result.setRenum(renum);
		Result.setResult(result);
		Result.setRsnum(rsnum);
		ResultService.insertResult(Result);
		return "redirect:toResult";
	}
	
	

	@RequestMapping("/toupdateResult")
	public String toupdateResult(Model model, Result Result, Integer id) throws IOException {
		Result=ResultService.selectResultById(id);
		model.addAttribute("result", Result);
		return "updateresult";
	}


	@RequestMapping("/updateResult")
	public String updateResult( Result Result, Integer id, Integer rsnum, Integer renum, String result) throws IOException {
		Result.setId(id);
		Result.setRenum(renum);
		Result.setResult(result);
		Result.setRsnum(rsnum);
		ResultService.updateMreultById(Result);
		return "redirect:toResult";
	}
	

	@RequestMapping("/deleteResult")
	public String deleteResult(Integer id) throws IOException {
		ResultService.deleteResultById(id);
		return "redirect:toResult";
	}
}
